package com.pro.controller;

import com.pro.pojo.JsonData;
import com.pro.pojo.SyUserOrder;
import com.pro.service.SyUserOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author 祖铭泽
 * @Date 2021/11/9/0009
 * @description 订单 控制层
 */
@Controller
@RequestMapping(value = "/SyUserOrder")
public class SyUserOrderController {
    @Autowired
    private SyUserOrderService syUserOrderService;

    //根据订单状态、订单来源、订单支付渠道查询订单
    @RequestMapping(value = "/getAllOrdersByStatusSourcePay")
    @ResponseBody
    public JsonData getAllOrdersByStatusSourcePay(SyUserOrder syUserOrder){
        List<SyUserOrder> allOrdersByStatusSourcePay = syUserOrderService.getAllOrdersByStatusSourcePay(syUserOrder);
        HashMap<String, Object> map = new HashMap<>();
        map.put("msg","");
        map.put("code",0);
        map.put("data",allOrdersByStatusSourcePay);
        return map.get("data") != null ? JsonData.buildSuccess(map) : JsonData.buildError("服务器出错了");
    }

    //删除当前订单
    @RequestMapping(value = "/deleteCurrentOrder")
    @ResponseBody
    public JsonData deleteCurrentOrder(Integer orderId){
        boolean deleteCurrentOrder = syUserOrderService.deleteCurrentOrder(orderId);
        return deleteCurrentOrder ? JsonData.buildSuccess("删除成功") : JsonData.buildError("删除失败");
    }

    //根据订单状态、订单来源、订单支付渠道查询订单
    @RequestMapping(value = "/getCourseOrdersByStatusSourcePay")
    @ResponseBody
    public JsonData getCourseOrdersByStatusSourcePay(SyUserOrder syUserOrder){
        List<SyUserOrder> courseOrdersByStatusSourcePay = syUserOrderService.getCourseOrdersByStatusSourcePay(syUserOrder);
        HashMap<String, Object> map = new HashMap<>();
        map.put("code",0);
        map.put("data",courseOrdersByStatusSourcePay);
        map.put("msg","");
        return map.get("data") != null ? JsonData.buildSuccess(map) : JsonData.buildError("服务器出错了");
    }

    //高级检索（课程名字、用户名字、用户手机号、订单号）
    @RequestMapping(value = "/getCourseOrdersAdvancedSearch")
    @ResponseBody
    public JsonData getCourseOrdersAdvancedSearch(SyUserOrder syUserOrder){
        List<SyUserOrder> courseOrdersAdvancedSearch = syUserOrderService.getCourseOrdersAdvancedSearch(syUserOrder);
        return courseOrdersAdvancedSearch != null ? JsonData.buildSuccess(courseOrdersAdvancedSearch) : JsonData.buildError("服务器出错了");
    }

    //高级检索（商品名字、用户名字、用户手机号、订单号）
    @RequestMapping(value = "/getProductOrdersAdvancedSearch")
    @ResponseBody
    public JsonData getProductOrdersAdvancedSearch(SyUserOrder syUserOrder){
        List<SyUserOrder> productOrdersAdvancedSearch = syUserOrderService.getProductOrdersAdvancedSearch(syUserOrder);
        return productOrdersAdvancedSearch != null ? JsonData.buildSuccess(productOrdersAdvancedSearch) : JsonData.buildError("服务器出错了");
    }

    //只查询正在处理中的商品订单
    @RequestMapping(value = "/getProductDisposeOrdersByStatusSourcePay")
    @ResponseBody
    public JsonData getProductDisposeOrdersByStatusSourcePay(SyUserOrder syUserOrder){
        List<SyUserOrder> productDisposeOrdersByStatusSourcePay = syUserOrderService.getProductDisposeOrdersByStatusSourcePay(syUserOrder);
        HashMap<String, Object> map = new HashMap<>();
        map.put("data",productDisposeOrdersByStatusSourcePay);
        map.put("msg","");
        map.put("code",0);
        return map.get("data") != null ? JsonData.buildSuccess(map) : JsonData.buildError("服务器出错了");
    }

    //查询正在处理中的状态数量
    @RequestMapping(value = "/getProductCountsByStatus")
    @ResponseBody
    public JsonData getProductCountsByStatus(Integer status){
        Integer productCountsByStatus = syUserOrderService.getProductCountsByStatus(status);
        return productCountsByStatus != null ? JsonData.buildSuccess(productCountsByStatus) : JsonData.buildError("服务器出错了");
    }

    //根据不同的订单状态查询不同的数据
    @RequestMapping(value = "/getProductDisposeOrdersByStatusPaySource")
    @ResponseBody
    public JsonData getProductDisposeOrdersByStatusPaySource(Integer status){
        List<SyUserOrder> productDisposeOrdersByStatusPaySource = syUserOrderService.getProductDisposeOrdersByStatusPaySource(status);
        HashMap<String, Object> map = new HashMap<>();
        map.put("data",productDisposeOrdersByStatusPaySource);
        map.put("code",0);
        map.put("msg","");
        return map.get("data") != null ? JsonData.buildSuccess(map) : JsonData.buildError("服务器出错了");
    }
    //查询状态为退订的商品订单
    @RequestMapping(value = "/getProductSalesReturnOrders")
    @ResponseBody
    public JsonData getProductSalesReturnOrders(SyUserOrder syUserOrder){
        List<SyUserOrder> productSalesReturnOrders = syUserOrderService.getProductSalesReturnOrders(syUserOrder);
        HashMap<String, Object> map = new HashMap<>();
        map.put("msg","");
        map.put("data",productSalesReturnOrders);
        map.put("code",0);
        return map.get("data") != null ? JsonData.buildSuccess(map) : JsonData.buildError("服务器出错了");
    }

    @RequestMapping(value = "/getProductCountsByAccomplishStatus")
    @ResponseBody
    public JsonData getProductCountsByAccomplishStatus(Integer createId){
        Integer productCountsByAccomplishStatus = syUserOrderService.getProductCountsByAccomplishStatus(createId);
        return productCountsByAccomplishStatus != null ? JsonData.buildSuccess(productCountsByAccomplishStatus) : JsonData.buildError("服务器出错了");
    }

    @RequestMapping(value = "/getProductCountsByStatusCreateId")
    @ResponseBody
    public JsonData getProductCountsByStatusCreateId(SyUserOrder syUserOrder){
        Integer productCountsByStatusCreateId = syUserOrderService.getProductCountsByStatusCreateId(syUserOrder);
        return productCountsByStatusCreateId != null ? JsonData.buildSuccess(productCountsByStatusCreateId) : JsonData.buildError("服务器出错了");
    }

    //查询订单状态为退货申请的订单
    @RequestMapping(value = "/getUnsubscribeApplyOrdersBySourcePay")
    @ResponseBody
    public JsonData getOrdersBySourcePay(SyUserOrder syUserOrder){
        LinkedList<SyUserOrder> orders = new LinkedList<>();
        List<SyUserOrder> productOrdersBySourcePay = syUserOrderService.getUnsubscribeApplyProductOrdersBySourcePay(syUserOrder);
        for (int i = 0; i < productOrdersBySourcePay.size(); i++) {
            orders.add(productOrdersBySourcePay.get(i));
        }
        List<SyUserOrder> courseOrdersBySourcePay = syUserOrderService.getUnsubscribeApplyCourseOrdersBySourcePay(syUserOrder);
        for (int i = 0; i < courseOrdersBySourcePay.size(); i++) {
            orders.add(courseOrdersBySourcePay.get(i));
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("data",orders);
        map.put("code",0);
        map.put("msg","");
        return map.get("data") != null ? JsonData.buildSuccess(map) : JsonData.buildError("服务器出错了");
    }

    //高级检索（课程名字、用户名字、用户手机号、订单号）并且正在申请处理的退订订单
    @RequestMapping(value = "/getUnsubscribeApplyOrdersByNameAccountPhoneNum")
    @ResponseBody
    public JsonData getUnsubscribeApplyOrdersByNameAccountPhoneNum(SyUserOrder syUserOrder){
        LinkedList<SyUserOrder> orders = new LinkedList<>();
        List<SyUserOrder> productOrdersBySourcePay = syUserOrderService.getUnsubscribeApplyProductOrdersByNameAccountPhoneNum(syUserOrder);
        for (int i = 0; i < productOrdersBySourcePay.size(); i++) {
            orders.add(productOrdersBySourcePay.get(i));
        }
        List<SyUserOrder> courseOrdersBySourcePay = syUserOrderService.getUnsubscribeApplyCourseOrdersByNameAccountPhoneNum(syUserOrder);
        for (int i = 0; i < courseOrdersBySourcePay.size(); i++) {
            orders.add(courseOrdersBySourcePay.get(i));
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("data",orders);
        map.put("code",0);
        map.put("msg","");
        return map.get("data") != null ? JsonData.buildSuccess(map) : JsonData.buildError("服务器出错了");
    }

    @RequestMapping(value = "/getAcceptedUnsubscribeOrders")
    @ResponseBody
    //查询订单状态为退货中、已退货的订单
    public JsonData getAcceptedUnsubscribeOrders(SyUserOrder syUserOrder){
        LinkedList<SyUserOrder> orders = new LinkedList<>();
        List<SyUserOrder> productOrdersBySourcePay = syUserOrderService.getAcceptedUnsubscribeProductOrders(syUserOrder);
        for (int i = 0; i < productOrdersBySourcePay.size(); i++) {
            orders.add(productOrdersBySourcePay.get(i));
        }
        List<SyUserOrder> courseOrdersBySourcePay = syUserOrderService.getAcceptedUnsubscribeCourseOrders(syUserOrder);
        for (int i = 0; i < courseOrdersBySourcePay.size(); i++) {
                orders.add(courseOrdersBySourcePay.get(i));
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("data",orders);
        map.put("code",0);
        map.put("msg","");
        return map.get("data") != null ? JsonData.buildSuccess(map) : JsonData.buildError("服务器出错了");
    }

    @RequestMapping(value = "/getAcceptedUnsubscribeOrdersByNameAccountPhoneNum")
    @ResponseBody
    //高级检索（商品/课程名字、用户名字、用户手机号、订单号）并且订单状态为退订中、已退订的退订商品订单
    public JsonData getAcceptedUnsubscribeOrdersByNameAccountPhoneNum(SyUserOrder syUserOrder){
        LinkedList<SyUserOrder> orders = new LinkedList<>();
        List<SyUserOrder> productOrdersBySourcePay = syUserOrderService.getAcceptedUnsubscribeProductOrdersByNameAccountPhoneNum(syUserOrder);
        for (int i = 0; i < productOrdersBySourcePay.size(); i++) {
            orders.add(productOrdersBySourcePay.get(i));
        }
        List<SyUserOrder> courseOrdersBySourcePay = syUserOrderService.getAcceptedUnsubscribeCourseOrdersByNameAccountPhoneNum(syUserOrder);
        for (int i = 0; i < courseOrdersBySourcePay.size(); i++) {
            orders.add(courseOrdersBySourcePay.get(i));
        }
        HashMap<String, Object> map = new HashMap<>();
        map.put("data",orders);
        map.put("code",0);
        map.put("msg","");
        return map.get("data") != null ? JsonData.buildSuccess(map) : JsonData.buildError("服务器出错了");
    }

    //根据不同的订单状态 查询课程订单数量
    @RequestMapping(value = "/getCourseOrderCounts")
    @ResponseBody
    public JsonData getCourseOrderCounts(Integer status){
        Integer courseOrderCounts = syUserOrderService.getCourseOrderCounts(status);
        return courseOrderCounts != null ? JsonData.buildSuccess(courseOrderCounts) : JsonData.buildError("服务器出错了");
    }
    //点击不同状态的按钮 切换不同的数据
    @RequestMapping(value = "/getCourseOrdersByStatus")
    @ResponseBody
    public JsonData getCourseOrdersByStatus(Integer status){
        List<SyUserOrder> courseOrdersByStatus = syUserOrderService.getCourseOrdersByStatus(status);
        return courseOrdersByStatus != null ? JsonData.buildSuccess(courseOrdersByStatus) : JsonData.buildError("服务器出错了");
    }
    //根据不同的订单状态 查询商品数量
    @RequestMapping(value = "/getProductOrderCounts")
    @ResponseBody
    public JsonData getProductOrderCounts(Integer status){
        Integer productOrderCounts = syUserOrderService.getProductOrderCounts(status);
        return productOrderCounts != null ? JsonData.buildSuccess(productOrderCounts) : JsonData.buildError("服务器出错了");
    }
    //点击不同状态的按钮 切换不同的数据
    @RequestMapping(value = "/getProductOrdersByStatus")
    @ResponseBody
    public JsonData getProductOrdersByStatus(Integer status){
        List<SyUserOrder> productOrdersByStatus = syUserOrderService.getProductOrdersByStatus(status);
        return productOrdersByStatus != null ? JsonData.buildSuccess(productOrdersByStatus) : JsonData.buildError("服务器出错了");
    }
    @RequestMapping(value = "/getAcceptedUnsubscribeOrderCounts")
    @ResponseBody
    public JsonData getAcceptedUnsubscribeOrderCounts(Integer status){
        Integer acceptedUnsubscribeOrderCounts = syUserOrderService.getAcceptedUnsubscribeOrderCounts(status);
        return acceptedUnsubscribeOrderCounts != null? JsonData.buildSuccess(acceptedUnsubscribeOrderCounts) : JsonData.buildError("服务器出错了");
    }
    @RequestMapping(value = "/getSyUserOrderById")
    @ResponseBody
    public JsonData getSyUserOrderById(Integer orderId){
        SyUserOrder syUserOrderById = syUserOrderService.getSyUserOrderById(orderId);
        return syUserOrderById != null ? JsonData.buildSuccess(syUserOrderById) : JsonData.buildError("服务器出错了");
    }
    @RequestMapping(value = "/getProductByOrderId")
    @ResponseBody
    public JsonData getProductByOrderId(Integer orderId){
        SyUserOrder syUserOrderById = syUserOrderService.getProductByOrderId(orderId);
        return syUserOrderById != null ? JsonData.buildSuccess(syUserOrderById) : JsonData.buildError("服务器出错了");
    }
    @RequestMapping(value = "/getAllOrderUpperCount")
    @ResponseBody
    public JsonData getAllOrderUpperCount(){
        int allOrderUpperCount = syUserOrderService.getAllOrderUpperCount();
        return allOrderUpperCount != 0 ? JsonData.buildSuccess(allOrderUpperCount) : JsonData.buildError("0");
    }
}
